home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / dec92.zip / 1012047A < prev    next >
Text File  |  1992-10-09  |  4KB  |  211 lines

  1. page ,132
  2.  
  3. ; masm tisr ; >err
  4.     .286p
  5. .xlist
  6. include ..\..\include\bogus.inc
  7. .list
  8.  
  9.  
  10. Words struc
  11. LoWord dw ?
  12. HiWord dw ?
  13. Words ends
  14.  
  15. EOI equ 020h            ; EOI command for PIC
  16.  
  17. INTA00 equ 020h         ; Master PIC control
  18. INTA01 equ 021h         ; Master PIC mask register
  19. INT_MASTER_0 equ 08h        ; Master PIC INT number
  20.  
  21. INTB00 equ 0A0h         ; Slave PIC control
  22. INTB01 equ 0A1h         ; Slave PIC mask register
  23. INT_SLAVE_0 EQU 70h        ; Slave PIC INT number
  24.  
  25. ;
  26. ; Set variables for our interrupt number
  27. ;
  28. ife (FAKE_IRQ GE 8)
  29. INT_DEV equ (INT_MASTER_0+(FAKE_IRQ AND 7))
  30. PIC00 equ INTA00
  31. PIC01 equ INTA01
  32. else
  33. INT_DEV equ (INT_SLAVE_0+(FAKE_IRQ AND 7))
  34. INT_MASK equ 1 SHL (FAKE_IRQ AND 7)
  35. PIC00 equ INTB00
  36. PIC01 equ INTB01
  37. endif
  38.  
  39. page
  40. CONST SEGMENT DWORD PUBLIC 'DATA'
  41. sdNoBogus db 'I do not see the bogus device.',0dh,0ah,'$'
  42. sdPrompt db 0Dh,0Ah,'S)tart, or Q)uit: ','$'
  43. sdCRLF    db 0Dh,0Ah,'$'
  44. sdDot    db '.','$'
  45.  
  46. CONST ENDS
  47.  
  48. DATA SEGMENT DWORD PUBLIC 'DATA'
  49. dwCount1 dw 0
  50. dwCount2 dw 0
  51. lpPrevISR dd 0            ; address of prior ISR
  52. fStopping db 0            ; TRUE when stopping
  53. DATA ENDS
  54.  
  55. STACK SEGMENT DWORD STACK 'STACK'
  56.     db    512 dup (?)
  57. STACK ENDS
  58.  
  59. DGroup GROUP CONST,DATA,STACK
  60.  
  61. page
  62.  
  63. ;IP    IntSvcRtn - The Interrupt Service Routine
  64. ;
  65. ;    WARNINGS
  66. ;
  67. ;    NOTES
  68. ;        This ISR generally increments an interrupt count (dwCount1)
  69. ;        and re-arms the device.
  70. ;
  71. ;        If the "fStopping" flag is set, the device is not re-armed.
  72. ;
  73.  
  74. FIXED_TEXT SEGMENT PARA PUBLIC 'CODE'
  75. segData1    dw    DGroup
  76.     assume    CS:FIXED_TEXT,DS:NOTHING
  77. IntSvcRtn proc far
  78.     push    ax
  79.     push    dx
  80.     push    ds
  81.     mov    ds,segData1
  82.     assume    ds:DGroup
  83.     inc    dwCount1
  84.     mov    al,NOT FAKE_CTL_EOI
  85.     mov    dx,FAKE_PORT
  86.     out    dx,al            ; send EOI to device
  87.     mov    al,EOI
  88.     out    PIC00,al        ; send EOI to PIC
  89. ife (PIC00 EQ INTA00)
  90.     out    INTA00,al        ; send EOI to master PIC, too
  91. endif
  92.     cmp    fStopping,0        ; exiting?
  93.     jnz    isr9            ; if so, then don't restart
  94.     mov    al,NOT FAKE_CTL_START
  95.     mov    dx,FAKE_PORT
  96.     out    dx,al            ; restart I/O
  97. isr9:
  98.     pop    ds
  99.     assume    ds:NOTHING
  100.     pop    dx
  101.     pop    ax
  102.     iret
  103. IntSvcRtn endp
  104.  
  105. FIXED_TEXT ENDS
  106.  
  107. page
  108. ;IP    __main - program entry point
  109. ;
  110. ;    NOTES
  111. ;        The user is prompted to S)tart or Q)uit the program.  If
  112. ;        "S" is selected, the programs enables interrupts and arms
  113. ;        the device, printing out a dot each time the device interrupts.
  114. ;
  115.  
  116. _TEXT SEGMENT PARA PUBLIC 'CODE'
  117. segData2    dw    DGroup
  118. segFixed    dw    FIXED_TEXT
  119.     assume    cs:_TEXT,ds:NOTHING
  120.  
  121. __main label far
  122.     mov    ds,segData2        ; Initialize default data segment
  123.     assume    ds:DGroup
  124.  
  125.     mov    dx,FAKE_PORT
  126.     in    al,dx            ; Is the bogus device present ?
  127.     or    al,al
  128.     jns    ml0            ; skip if so
  129.     mov    dx,OFFSET DGroup:sdNoBogus
  130.     mov    ah,9
  131.     int    21h            ; else print error message
  132.     mov    ax,4C01h
  133.     int    21h            ; and exit
  134.  
  135. ml0:
  136.     mov    ax,3500h+INT_DEV
  137.     cli
  138.     int    21h            ; Query the current ISR
  139.     mov    lpPrevISR.LoWord,bx
  140.     mov    lpPrevISR.HiWord,es ; Save it
  141.  
  142.     mov    dx,OFFSET FIXED_TEXT:IntSvcRtn
  143.     push    ds
  144.     mov    ds,segFixed
  145.     assume    ds:NOTHING
  146.     mov    ax,2500h+INT_DEV
  147.     int    21h            ; Set our ISR
  148.     pop    ds
  149.     assume    ds:DGroup
  150.     sti
  151.  
  152.     mov    dx,OFFSET DGroup:sdPrompt
  153.     mov    ah,9
  154.     int    21h            ; "S)tart or Q)uit
  155.  
  156. ml1:
  157.     mov    dl,0FFh
  158.     mov    ah,6
  159.     int    21h            ; read from console, nowait
  160.     jz    ml3
  161.     or    al,40h
  162.     cmp    al,'q'
  163.     je    ml8            ; skip if "Q" pressed
  164.     cmp    al,'s'
  165.     jne    ml3            ; skip if "S" not pressed
  166.     cli
  167.     in    al,PIC01        ; unmask the interrupt
  168.     and    al,NOT INT_MASK
  169.     out    PIC01,al
  170.     sti
  171.     mov    al,NOT FAKE_CTL_START
  172.     mov    dx,FAKE_PORT
  173.     out    dx,al            ; start device I/O
  174. ml3:
  175.     mov    ax,dwCount1
  176.     cmp    ax,dwCount2
  177.     je    ml4            ; skip if the count of interrupts unchanged
  178.     mov    dwCount2,ax
  179.     mov    dx,OFFSET DGroup:sdDot
  180.     mov    ah,9
  181.     int    21h            ; else, display a dot
  182. ml4:
  183.     jmp    ml1            ; loop for more
  184.  
  185. ml8:
  186.     mov    fStopping,1        ; Tell the ISR to stop
  187.     mov    dx,FAKE_PORT
  188. ml9:
  189.     in    al,dx
  190.     rcr    al,1
  191.     jnc    ml9            ; loop while busy
  192.  
  193.     cli
  194.     in    al,PIC01
  195.     or    al,INT_MASK
  196.     out    PIC01,al        ; mask the interrupt level
  197.     sti
  198.  
  199.     push    ds
  200.     lds    dx,lpPrevISR
  201.     assume    ds:NOTHING
  202.     mov    ax,2500h+INT_DEV
  203.     int    21h            ; restore the previous ISR
  204.     pop    ds
  205.     assume    ds:DGroup
  206.     mov    ax,4C00h
  207.     int    21h            ; exit
  208. _TEXT ENDS
  209.  
  210.     end    __main
  211.